<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/js/axios.min.js"></script>
<script src="/js/util.js"></script>
<script>
   function add(){
       clear();
       var gender;
       document.getElementsByName("gender").forEach(n=>{
           if (n.checked){
               gender=n.value;
           }
       })

       axios.get("/user/add",{
           params:{
               username:$("username").value,
               gender,
               salary:$("salary").value,
               birthday:$("birthday").value
           }
       }).then(resp=>{
           var info = resp.data;
           console.log(info);
           if (info=="ok"){
               location.href="/index.html";
           }else {
               for (let i = 0; i < info.length; i++) {
                   $(info[i].field+"Span").innerHTML=info[i].defaultMessage;
               }
           }
       })
   }

   function clear(){
       $("usernameSpan").innerHTML="";
       $("genderSpan").innerHTML="";
       $("salarySpan").innerHTML="";
       $("birthdaySpan").innerHTML="";
   }
</script>
<body>
用户名：<input type="text" id="username"><br>
<span id="usernameSpan"></span><br>
性别：<input type="radio" name="gender" value="男" checked>男
<input type="radio" name="gender" value="女">女<br>
<span id="genderSpan"></span><br>
工资：<input type="text" id="salary"><br>
<span id="salarySpan"></span><br>
生日：<input type="date" id="birthday"><br>
<span id="birthdaySpan"></span><br>
<input type="button" value="注册" onclick="add()">
</body>
</html>